package com.situ.blog.service.impl;


import com.situ.blog.dao.IBlogDao;
import com.situ.blog.dao.impl.BlogDaoImpl;
import com.situ.blog.pojo.entity.Blog;
import com.situ.blog.pojo.query.BlogQuery;
import com.situ.blog.service.IBlogService;
import com.situ.blog.util.LayUITableResult;

import java.util.List;

public class BlogServiceImpl implements IBlogService {
    private IBlogDao blogDao = new BlogDaoImpl();

    //业务：为了封装PageInfo，查询两次数据库
    @Override
    public LayUITableResult selectByPage(BlogQuery blogQuery) {
        List<Blog> list = blogDao.selectByPage(blogQuery);
        Integer totalCount = blogDao.selectTotalCount(blogQuery);
        //int totalPage = (int)Math.ceil((double)totalCount / pageSize);

        return LayUITableResult.ok(totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        blogDao.deleteById(id);
    }

    @Override
    public void add(Blog blog) {
        blogDao.add(blog);
    }


    @Override
    public void deleteAll(String[] ids) {
        // delete from blog where id in();
        for (String id : ids) {
            blogDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void updateStatus(int id, int status) {
        blogDao.updateStatus(id, status);
    }
}
